﻿using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Drawing;
using IronOne.SalesOne.BusinessObjects;

namespace IronOne.SalesOne.SalesOneWeb.UserManagement
{

    public partial class CreateUserType : SOSecurityPage
    {
        Facade.StructureFacade structureFacade = new Facade.StructureFacade();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SetCredentials(ValidateUserCredentials(Request.Url.LocalPath));

                lblError.ForeColor = Color.Black;
                lblError.Text = "";
            }
            catch { MassageSummery("IIS514"); }
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                string strUserTypeName = txtUserTypeName.Text.Trim();

                if (structureFacade.GetUserTypeByName(strUserTypeName).Count < 1)
                {
                    UserType userType = new UserType();

                    userType.UserTypeName = strUserTypeName;
                    userType.LoweredUserTypeName = strUserTypeName.ToLower();
                    userType.Description = txtDescription.Text;

                    structureFacade.InsertUserType(userType);

                    MassageSummery("IIS401");
                }
                else
                {
                    MassageSummery("IIS506");
                }
            }
            catch
            {
                MassageSummery("IIS401");
            }
            
        }

        public void SetCredentials(StringCollection credential)
        {
            foreach (string item in credential)
            {
                if (item.ToLower() == "c")
                    btnCreate.Visible = true;
            }
        }
    }
}
